//
//  WBTitleButton.swift
//  weiboswift
//
//  Created by dingzhibing on 2017/4/19.
//  Copyright © 2017年 dingzhibing. All rights reserved.
//

import UIKit

class WBTitleButton: UIButton {
    init(title:String?){
        //title如果是nil，就显示“首页”  不显示箭头
        
        super.init(frame:CGRect())
        
        if title == nil{
            setTitle("首页", for: [])
        }else{
            setTitle(title!, for: [])
            self.setImage(UIImage(named:"navigationbar_arrow_down"), for: [])
            self.setImage(UIImage(named:"navigationbar_arrow_up"), for: UIControlState.selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray, for: [])
        
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    //重新布局子视图
//    override func layoutSubviews() {
//        super.layoutSubviews()
//        
//        //判断 label 和imageview是否同时存在
//        guard let titleLabel = titleLabel, let imageView = imageView else {
//            return
//        }
//        print("\(titleLabel.bounds.width) \(imageView.bounds.width)")
//        
////        titleLabel.frame = titleLabel.frame.offsetBy(dx: -imageView.bounds.width, dy: 0)
////        imageView.frame = imageView.frame.offsetBy(dx: 0, dy: 0)
//        print("\(titleLabel.bounds.width) \(imageView.bounds.width)")
//    }
}
